package com.ruoyi.fun.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.fun.mapper.EcAnnouncementMapper;
import com.ruoyi.fun.domain.EcAnnouncement;
import com.ruoyi.fun.service.IEcAnnouncementService;

/**
 * 公告Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-08-08
 */
@Service
public class EcAnnouncementServiceImpl implements IEcAnnouncementService 
{
    @Autowired
    private EcAnnouncementMapper ecAnnouncementMapper;

    /**
     * 查询公告
     * 
     * @param announcementId 公告主键
     * @return 公告
     */
    @Override
    public EcAnnouncement selectEcAnnouncementByAnnouncementId(Long announcementId)
    {
        return ecAnnouncementMapper.selectEcAnnouncementByAnnouncementId(announcementId);
    }

    /**
     * 查询公告列表
     * 
     * @param ecAnnouncement 公告
     * @return 公告
     */
    @Override
    public List<EcAnnouncement> selectEcAnnouncementList(EcAnnouncement ecAnnouncement)
    {
        System.out.println("[DEBUG] EcAnnouncementServiceImpl.selectEcAnnouncementList - 查询参数 orgId: " + ecAnnouncement.getOrgId());
        List<EcAnnouncement> result = ecAnnouncementMapper.selectEcAnnouncementList(ecAnnouncement);
        System.out.println("[DEBUG] EcAnnouncementServiceImpl.selectEcAnnouncementList - 查询结果数量: " + result.size());
        for (EcAnnouncement announcement : result) {
            System.out.println("[DEBUG] EcAnnouncementServiceImpl.selectEcAnnouncementList - 公告ID: " + announcement.getAnnouncementId() + ", orgId: " + announcement.getOrgId());
        }
        return result;
    }

    /**
     * 新增公告
     * 
     * @param ecAnnouncement 公告
     * @return 结果
     */
    @Override
    public int insertEcAnnouncement(EcAnnouncement ecAnnouncement)
    {
        ecAnnouncement.setCreateTime(DateUtils.getNowDate());
        ecAnnouncement.setOrgId(SecurityUtils.getDeptId());
        return ecAnnouncementMapper.insertEcAnnouncement(ecAnnouncement);
    }

    /**
     * 修改公告
     * 
     * @param ecAnnouncement 公告
     * @return 结果
     */
    @Override
    public int updateEcAnnouncement(EcAnnouncement ecAnnouncement)
    {
        ecAnnouncement.setUpdateTime(DateUtils.getNowDate());
        return ecAnnouncementMapper.updateEcAnnouncement(ecAnnouncement);
    }

    /**
     * 批量删除公告
     * 
     * @param announcementIds 需要删除的公告主键
     * @return 结果
     */
    @Override
    public int deleteEcAnnouncementByAnnouncementIds(Long[] announcementIds)
    {
        return ecAnnouncementMapper.deleteEcAnnouncementByAnnouncementIds(announcementIds);
    }

    /**
     * 删除公告信息
     * 
     * @param announcementId 公告主键
     * @return 结果
     */
    @Override
    public int deleteEcAnnouncementByAnnouncementId(Long announcementId)
    {
        return ecAnnouncementMapper.deleteEcAnnouncementByAnnouncementId(announcementId);
    }

    /**
     * 根据announcementId和组织ID查询Announcement
     * 
     * @param announcementId Announcement主键
     * @param orgId 组织ID
     * @return Announcement
     */
    @Override
    public EcAnnouncement selectEcAnnouncementByAnnouncementIdAndOrgId(Long announcementId, Long orgId)
    {
        return ecAnnouncementMapper.selectEcAnnouncementByAnnouncementIdAndOrgId(announcementId, orgId);
    }

    /**
     * 根据组织ID查询Announcement列表
     * 
     * @param ecannouncement Announcement
     * @param orgId 组织ID
     * @return Announcement集合
     */
    @Override
    public List<EcAnnouncement> selectEcAnnouncementListByOrgId(EcAnnouncement ecannouncement, Long orgId)
    {
        return ecAnnouncementMapper.selectEcAnnouncementListByOrgId(ecannouncement, orgId);
    }
}